Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Constraint refactoring#1415

Merged
tli2 merged 24 commits intocmu-db:masterfrom
ksaito7:pg_constraint
Jul 3, 2018
Merged

Constraint refactoring#1415
tli2 merged 24 commits intocmu-db:masterfrom
ksaito7:pg_constraint

Conversation

@ksaito7
Copy link
Copy Markdown
Contributor

@ksaito7 ksaito7 commented Jun 18, 2018

This PR refactors constraint stuff related to planner, executor, storage and catalog.

- Contributions

  1. Add a new catalog table for constraints: pg_constraint
  2. Clean up data structures of constraints and its usage:
    Table constraint (Primary key, Foreign key, Unique, Check) -> Constraint (pg_constraint)
    Column constraint (Not null, Default) -> Column (pg_attribute)
    Deleted class -> ForeignKey, MultiConstraint
  3. Add set/add/drop constraint functions in Catalog.
  4. Simplify checking of constraints in DataTable when inserting/updating.

- Related Issues

  1. Store foreign keys into a catalog table #1270

- Remaining Issues

  1. Parser does not support multiple column UNIQUE constraint.
  2. CHECK constraints doesn't work when inserting/updating.
  3. CHECK constraints doesn't support multiple columns or complex formula.
  4. DDL: ADD/SET/DROP constraints are not supported.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 18, 2018

Coverage Status

Coverage increased (+0.08%) to 76.512% when pulling 25a3d0c on ksaito7:pg_constraint into c949481 on cmu-db:master.

@tli2 tli2 requested a review from apavlo June 19, 2018 14:40
@tli2
Copy link
Copy Markdown
Contributor

tli2 commented Jun 19, 2018

@ksaito7 It looks like it will conflict with #1414 like crazy. Do you mind if you rebase on that PR locally?

@tli2
Copy link
Copy Markdown
Contributor

tli2 commented Jun 19, 2018

@apavlo Joy wrote the original code and nobody has touched that code in a long time. I don't know if anybody else understands it so can you take a look?

@ksaito7
Copy link
Copy Markdown
Contributor Author

ksaito7 commented Jun 19, 2018

@tli2 Sure, I will rebase locally, and fix all tabs.

@apavlo apavlo requested review from db-ol and removed request for apavlo June 21, 2018 15:21
Copy link
Copy Markdown
Contributor

@db-ol db-ol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant calls and unused variables. Revise incorrect comments. And some possible testing improvements.

Comment thread src/catalog/catalog.cpp Outdated

// Insert column info into each catalog
oid_t column_id = 0;
std::vector<oid_t> pkey_attrs, unique_attrs;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables are unused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete them.

Comment thread src/catalog/catalog.cpp Outdated
// Insert column info into each catalog
oid_t column_id = 0;
std::vector<oid_t> pkey_attrs, unique_attrs;
std::shared_ptr<Constraint> pkey_constraint, unique_constraint;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables are also unused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete them.

Comment thread src/catalog/catalog.cpp Outdated
->GetSchema();

// Create index
std::stringstream index_name(table_object->GetTableName().c_str());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant call to c_str()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete it.

Comment thread src/catalog/catalog.cpp Outdated
src_table_oid, txn);
auto src_schema = src_table->GetSchema();

std::stringstream index_name(src_table_object->GetTableName().c_str());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant call to c_str()

Comment thread src/catalog/constraint_catalog.cpp Outdated

/*@brief Insert a constraint into the pg_constraint table
* This targets PRIMARY KEY, FOREIGN KEY, UNIQUE or CHECK constraint
* @param table_oid oid of the table related to this constraint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table_oid is not in the parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete redundant comments.

Comment thread test/catalog/catalog_test.cpp Outdated
auto salary = catalog->GetTableObject("emp_db", DEFAULT_SCHEMA_NAME,
"salary_table", txn);

catalog->AddPrimaryKeyConstraint(emp->GetDatabaseOid(), emp->GetTableOid(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add PrimaryKey constraints in the CreatingTable test and without verifying it?

Copy link
Copy Markdown
Contributor Author

@ksaito7 ksaito7 Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not adding, but just fixing. These might be used in other test? Verifying for primary keys is done in ConstraintCatalogTest.

Comment thread test/catalog/catalog_test.cpp Outdated

catalog->AddPrimaryKeyConstraint(emp->GetDatabaseOid(), emp->GetTableOid(),
{0}, "con_primary", txn);
catalog->AddPrimaryKeyConstraint(department->GetDatabaseOid(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add PrimaryKey constraints in the CreatingTable test and without verifying it?

Comment thread test/catalog/catalog_test.cpp Outdated
catalog->AddPrimaryKeyConstraint(department->GetDatabaseOid(),
department->GetTableOid(), {0},
"con_primary", txn);
catalog->AddPrimaryKeyConstraint(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add PrimaryKey constraints in the CreatingTable test and without verifying it?

LOG_DEBUG("%s", con_table->GetSchema()->GetInfo().c_str());
LOG_DEBUG("Complete check for constraint table");

// Drop constraint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if we can verify it after dropping constraints?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Add verifying.

table->AddIndex(pkey_index);

// Create primary key constraint on the table
if (need_primary_index) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be need_primary_index or need_primary_key?

Copy link
Copy Markdown
Contributor Author

@ksaito7 ksaito7 Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it to need_primary_key.

@tli2 tli2 merged commit 898219f into cmu-db:master Jul 3, 2018
@ksaito7 ksaito7 mentioned this pull request Jul 5, 2018
tli2 added a commit that referenced this pull request Jul 6, 2018
@mbutrovich mbutrovich mentioned this pull request Jul 6, 2018
tli2 pushed a commit that referenced this pull request Jul 6, 2018
* Revert "Constraint refactoring (#1415)"

This reverts commit 898219f
mtunique pushed a commit to mtunique/peloton that referenced this pull request Apr 16, 2019
* Add pg_constraint catalog table

* Reconstruct constraints
mtunique pushed a commit to mtunique/peloton that referenced this pull request Apr 16, 2019
* Revert "Constraint refactoring (cmu-db#1415)"

This reverts commit 898219f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants